package com.haidong.controller;

import com.haidong.domain.User;
import org.springframework.web.bind.annotation.*;

// 对于没有推送网页的类,可以全局加上ResponseBody
@RestController // @ResponseBody + @Controller
@RequestMapping("/users")
public class UserController {

    // 使用这些注解替代重复书写的method方法
    @PostMapping
    public String save(@RequestBody User user) {
        System.out.println("user save..."+user);
        return "{'module':'user save'}";
    }

    @DeleteMapping("/{id}/{name}")
    // 参数映射名一样也可以加上PathVariable,节省框架性能
    public String delete(@PathVariable("id") Integer userId,@PathVariable String name) {
        System.out.println("user delete..." + userId +name);
        return "{'module':'user delete'}";
    }

    @PutMapping
    public String update(@RequestBody User user) {
        System.out.println("user update..." + user);
        return "{'module':'user update'}";
    }

    @GetMapping("/{id}")
    public String getById(@PathVariable Integer id) {
        System.out.println("user getById..." + id);
        return "{'module':'user getById'}";
    }

    @GetMapping
    public String getAll() {
        System.out.println("user getAll...");
        return "{'module':'user getAll'}";
    }
}
